<template>
  <section>
    <!-- 面包屑 -->
      <breadcrumbs></breadcrumbs>
    <btns @exec="exec"></btns>
    <div class="data-container scroll-table">
      <div>
        <div class="ind-title lh50 f16">课程列表</div>
      </div>
      <el-table :data="tableData" style="width: 100%" row-key="dictId" border @selection-change="tableSelectionChange">
        <el-table-column type="selection" width="40"> </el-table-column>
        <el-table-column label="课程标题" prop="title" align="center">
        </el-table-column>
        <el-table-column label="年级" prop="grade" align="center">
        </el-table-column>
        <el-table-column prop="courseType" label="类型" align="center">
          <template slot-scope="scope">
            <p v-if="scope.row.courseType == 1">
              道德与法治
            </p>
            <p v-if="scope.row.courseType == 2">
              主题教育
            </p>
            <p v-if="scope.row.courseType == 3">
              成长与信仰
            </p>
          </template>
        </el-table-column>
        <el-table-column label="版本" prop="version" align="center">
        </el-table-column>
        <el-table-column label="教材" prop="textbook" align="center">
        </el-table-column>
        <el-table-column label="封面" width="140" align="center">
          <template slot-scope="scope">
            <img :src="scope.row.headImg" alt="" class="img-feng">
          </template>
        </el-table-column>
        <el-table-column prop="state" label="状态" width="50" align="center">
          <template slot-scope="scope">
            <p v-if="scope.row.state == 1">
              有效
            </p>
            <p v-if="scope.row.state == 2">
              审核中
            </p>
            <p v-if="scope.row.state == 3">
              无效
            </p>
          </template>
        </el-table-column>
        <el-table-column prop="state" label="是否是直播课程" align="center">
          <template slot-scope="scope">
            <p v-if="scope.row.isOpen == 1">
              是
            </p>
            <p v-if="scope.row.isOpen == 0">
              否
            </p>
          </template>
        </el-table-column>
        <el-table-column label="生效时间" prop="checktime" width="135" align="center">
          <template slot-scope="scope">
            <p v-if="scope.row.checktime!=''&&scope.row.checktime!=undefined">{{scope.row.checktime}}</p>
            <p v-else>暂无</p>
          </template>
        </el-table-column>
        <el-table-column label="新增时间" width="135" prop="addtime" align="center">
        </el-table-column>
        <el-table-column prop="name" label="用户操作" width="300" align="center">
          <template slot-scope="scope">
            <!-- <el-button type="text" size="small" @click="goClassDetail(scope.row)">查看</el-button> -->
            <el-button type="text" size="small" @click="goCommentList(scope.row)">查看评论列表</el-button>
            <el-button type="text" size="small" @click="goOrderList(scope.row,1)">管理课程内容</el-button>
            <el-button @click="goOrderList(scope.row,2)" type="text" size="small">管理课程关联</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pages">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[5, 10, 15, 20]"
                     :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total">
      </el-pagination>
    </div>
    <el-dialog title="添加课程信息" :visible.sync="dialogCreateFormVisible">
      <el-form :model="createForm" label-width="120px" ref="createForm" :rules="rules">
        <el-form-item label="标题" prop="title">
          <el-input v-model="createForm.title" placeholder="请输入课程标题"></el-input>
        </el-form-item>
        <el-form-item label="课程类型" prop="courseType">
          <el-select v-model="createForm.courseType" @change="changeType" placeholder="请选择课程类型">
            <el-option v-for="item in courseTyeList" :label="item.label" :value="item.id" :key="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="分类" v-if="(createForm.courseType!=''&&createForm.courseType!=undefined)&&createForm.courseType==3" prop="defId">
          <el-select v-model="createForm.defId" placeholder="请选择分类">
            <el-option v-for="item in defList" :label="item.dictName" :value="item.dictPid" :key="item.dictPid"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="年级" v-if="(createForm.courseType!=''&&createForm.courseType!=undefined)&&(createForm.courseType==1||createForm.courseType==2)"
                      prop="gradeId">
          <el-select v-model="createForm.gradeId" placeholder="请选择年级" @change="changeTypeByGradeId">
            <el-option v-for="item in gradeList" :label="item.dictName" :value="item.dictPid" :key="item.dictPid"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="教材" v-if="(createForm.courseType!=''&&createForm.courseType!=undefined)&&(createForm.courseType==1)" prop="textbookId">
          <el-select v-model="createForm.textbookId" placeholder="请选择教材" @change="changeTypeByTextbookId">
            <el-option v-for="item in textbookList" :label="item.dictName" :value="item.dictPid" :key="item.dictPid"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="单元" v-if="(createForm.courseType!=''&&createForm.courseType!=undefined)&&(createForm.courseType==1)" prop="unitId">
          <el-select v-model="createForm.unitId" placeholder="请选择单元">
            <el-option v-for="item in unitList" :label="item.dictName" :value="item.dictPid" :key="item.dictPid"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="版本" v-if="(createForm.courseType!=''&&createForm.courseType!=undefined)&&(createForm.courseType==1)" prop="versionId">
          <el-select v-model="createForm.versionId" placeholder="请选择版本">
            <el-option v-for="item in versionList" :label="item.dictName" :value="item.dictPid" :key="item.dictPid"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="类型" v-if="(createForm.courseType!=''&&createForm.courseType!=undefined)&&(createForm.courseType==1||createForm.courseType==2)"
                      prop="moldId">
          <el-select v-model="createForm.moldId" placeholder="请选择类型">
            <el-option v-for="item in moldList" :label="item.dictName" :value="item.dictPid" :key="item.dictPid"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="课程封面" prop="headImg" :label-width="formLabelWidth">
          <el-upload :action="importFileUrl" v-model="createForm.headImg" list-type="picture-card" :before-upload="beforeAvatarUpload" :auto-upload="true"
                     :on-success="getUrl" :accept="'image/*'" :show-file-list="false">
            <img v-if="hasFile" :src="createAddfile" class="img-feng" alt="图片" />
            <i v-else class="el-icon-plus"></i>
          </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogCreateFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="addCourse('createForm')">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="修改banner信息" :visible.sync="dialogEditFormVisible">
      <el-form :model="EditForm" label-width="120px" ref="EditForm" :rules="rules">
        <el-form-item label="标题" prop="title">
          <el-input v-model="EditForm.title" placeholder="请输入课程标题"></el-input>
        </el-form-item>
        <el-form-item label="课程类型" prop="courseType">
          <el-select v-model="EditForm.courseType" @change="changeType" placeholder="请选择课程类型">
            <el-option v-for="item in courseTyeList" :label="item.label" :value="item.id" :key="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="分类" v-if="(EditForm.courseType!=''&&EditForm.courseType!=undefined)&&EditForm.courseType==3" prop="defId">
          <el-select v-model="EditForm.defId" placeholder="请选择分类">
            <el-option v-for="item in defList" :label="item.dictName" :value="item.dictPid" :key="item.dictPid"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="年级" v-if="(EditForm.courseType!=''&&EditForm.courseType!=undefined)&&(EditForm.courseType==1||EditForm.courseType==2)"
                      prop="gradeId">
          <el-select v-model="EditForm.gradeId" placeholder="请选择年级" @change="changeTypeByGradeId">
            <el-option v-for="item in gradeList" :label="item.dictName" :value="item.dictPid" :key="item.dictPid"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="教材" v-if="(EditForm.courseType!=''&&EditForm.courseType!=undefined)&&(EditForm.courseType==1)" prop="textbookId">
          <el-select v-model="EditForm.textbookId" placeholder="请选择教材" @change="changeTypeByTextbookId">
            <el-option v-for="item in textbookList" :label="item.dictName" :value="item.dictPid" :key="item.dictPid"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="单元" v-if="(EditForm.courseType!=''&&EditForm.courseType!=undefined)&&(EditForm.courseType==1)" prop="unitId">
          <el-select v-model="EditForm.unitId" placeholder="请选择单元">
            <el-option v-for="item in unitList" :label="item.dictName" :value="item.dictPid" :key="item.dictPid"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="版本" v-if="(EditForm.courseType!=''&&EditForm.courseType!=undefined)&&(EditForm.courseType==1)" prop="versionId">
          <el-select v-model="EditForm.versionId" placeholder="请选择版本">
            <el-option v-for="item in versionList" :label="item.dictName" :value="item.dictPid" :key="item.dictPid"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="类型" v-if="(EditForm.courseType!=''&&EditForm.courseType!=undefined)&&(EditForm.courseType==1||EditForm.courseType==2)"
                      prop="moldId">
          <el-select v-model="EditForm.moldId" placeholder="请选择类型">
            <el-option v-for="item in moldList" :label="item.dictName" :value="item.dictPid" :key="item.dictPid"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="课程封面" prop="headImg" :label-width="formLabelWidth">
          <el-upload :action="importFileUrl" v-model="EditForm.headImg" list-type="picture-card" :before-upload="beforeAvatarUpload" :auto-upload="true"
                     :on-success="getUrl" :accept="'image/*'" :show-file-list="false">
            <img v-if="hasFile" :src="createAddfile" class="img-feng" alt="图片" />
            <i v-else class="el-icon-plus"></i>
          </el-upload>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogEditFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="editBanner('EditForm')">确 定</el-button>
      </div>
    </el-dialog>
  </section>
</template>

<script>
import btns from "@/components/btns.vue";
import Editor from "@/components/edit";
import breadcrumbs from "@/components/breadcrumbs.vue";
export default {
  components: {
    btns,
    Editor,
    breadcrumbs,
  },
  data() {
    var FengValidate = (rule, value, callback) => {
      // console.log(this.addfile);
      if (this.addfile == "") {
        callback(new Error("请选择封面图片"));
      }
      // if (value == null || value == '') {
      //   this.activeNames = ['2'];
      // }
    };
    return {
      Editlink: "",
      EditAddfile: "",
      createAddfile: "",
      hasFile: false,
      isShowGoodsListEdit: false,
      isShowProductListEdit: false,
      isShowFengEdit: false,
      isShowEditedit: false,
      EditForm: {},
      dialogEditFormVisible: false,
      isShowGoodsList: false,
      isShowProductList: false,
      isShowFeng: false,
      ProductList: [],
      GoodsList: [],
      isShow: false,
      Adaddfile: "",
      searchForm: {
        name: ""
      },
      tableData: [],
      tableSelection: [],
      currentPage: 1,
      pageSize: 5,
      total: 0,
      dialogCreateFormVisible: false,
      createForm: {},
      formLabelWidth: "120px",
      addfile: "",
      importFileUrl: this.GLOBAL.imgBaseUrl,
      isShowEdit: false,
      bannerList: [{
        id: 1,
        label: "小程序首页轮播"
      },
      {
        id: 2,
        label: "小程序首页固定"
      },
      {
        id: 3,
        label: "pc端道德与法治"
      },
      {
        id: 4,
        label: "pc端主题教育"
      },
      {
        id: 5,
        label: "pc端成长与信仰"
      },
      ],
      bannerTypeList: [{
        id: 1,
        label: "无关联"
      },
      {
        id: 2,
        label: "课程"
      },
      {
        id: 3,
        label: "新闻资讯"
      },
      {
        id: 4,
        label: "学术引领"
      },
      {
        id: 5,
        label: "培训"
      },
      {
        id: 5,
        label: "研修"
      },
      ],
      courseTyeList: [{
        id: 1,
        label: "道德与法治"
      },
      {
        id: 2,
        label: "主题教育"
      },
      {
        id: 3,
        label: "成长与信仰"
      }
      ],
      defList: [],
      gradeList: [],
      moldList: [],
      teacherList: [],
      textbookList: [],
      unitList: [],
      versionList: [],
      rules: {
        // name: [
        //   { required: true, message: '请输入banner名称', trigger: 'blur' },
        //   // { validator: allNumValidate, trigger: 'blur' }
        // ],
        title: [{
          required: true,
          message: "请输入课程标题",
          trigger: "blur"
        },
          // { validator: allNumValidate, trigger: 'blur' }
        ],
        courseType: [{
          required: true,
          message: "请选择banner类型",
          trigger: "change"
        },
          // { validator: allNumValidate, trigger: 'blur' }
        ],
        defId: [{
          required: true,
          message: "请选择分类",
          trigger: "change"
        },
          // { validator: allNumValidate, trigger: 'blur' }
        ],
        gradeId: [{
          required: true,
          message: '请选择年级',
          trigger: 'change'
        },
          // { validator: FengValidate, trigger: "change" },
        ],
        textbookId: [{
          required: true,
          message: "请选择教材",
          trigger: "change"
        },
          // { validator: allNumValidate, trigger: 'blur' }
        ],
        unitId: [{
          required: true,
          message: "请选择单元",
          trigger: "change"
        },
          // { validator: allNumValidate, trigger: 'blur' }
        ],
        moldId: [{
          required: true,
          message: "请选择类型",
          trigger: "change"
        },
          // { validator: allNumValidate, trigger: 'blur' }
        ],
        versionId: [{
          required: true,
          message: "请选择版本",
          trigger: "change"
        },
          // { validator: allNumValidate, trigger: 'blur' }
        ],
        headImg: [{
          required: true,
          message: "请选择封面图片",
          trigger: "change"
        },
          // { validator: allNumValidate, trigger: 'blur' }
        ],

      },
    };
  },
  created() {
    this.getList(this.currentPage, this.pageSize);
    // this.getGoodsList();
    // this.getProductList();
  },
  methods: {
    refresh() {
      this.getList(this.currentPage, this.pageSize);
    },
    changeType(index) {
      console.log(index)
      if (index == 1) {
        this.getListByCode("ddfz_nj", 1);
        this.getListByCode("ddfz_lx", 2)
        this.getListByCode("ddfz_bb", 3)
      } else if (index == 2) {
        this.gradeList = this.getListByCode("ddfz_nj", 1);
        this.getListByCode("ddfz_lx", 2)
      } else if (index == 3) {
        this.getListByCode("czxy_fl", 4)
      }
      console.log(this.gradeList, this.moldList, this.versionList, this.moldList, this.defList)
    },
    changeTypeByGradeId(id) {
      this.getListById(id, 5)
    },
    changeTypeByTextbookId(id) {
      this.getListById(id, 6)
    },
    getListByCode(code, index) {
      this.$api.dict.getDictListByparentCode({
        dictcode: code
      }).then((res) => {
        if (res.code == 200) {
          if (index == 1) {
            this.gradeList = res.data
          } else if (index == 2) {
            this.moldList = res.data;
          } else if (index == 3) {
            this.versionList = res.data
          } else if (index == 4) {
            this.defList = res.data
          }
          // res.data
        }
      })
    },
    getListById(id, index) {
      this.$api.dict.getDictListBypid({
        pid: id
      }).then((res) => {
        if (res.code == 200) {
          if (index == 5) {
            this.textbookList = res.data;
          } else if (index == 6) {
            this.unitList = res.data;
          }
        }
      })
    },
    goCommentList(row) {
      this.$router.push({
        path: `/comment/list`,
        query: {
          id: row.courseId
        }
      })
    },
    goOrderList(row, index) {
      // index为1，表示课程内容列表； 为2，表示课程关联列表
      if (index == 1) {
        this.$router.push({
          path: `/class/list/Contentlist`,
          query: {
            id: row.courseId
          }
        })
      } else {
        this.$router.push({
          path: `/class/list/Relationlist`,
          query: {
            id: row.courseId
          }
        })
      }

    },
    //启用
    enable() {
      if (this.tableSelection.length < 1) {
        this.$message.error("请选择要操作的数据！");
        return;
      }
      let ids = this.tableSelection.map((e) => {
        return e.state;
      });
      let courseId = this.tableSelection.map((e) => {
        return e.courseId;
      });
      let s = new Set(ids);
      if ([...s].length != 1) {
        return this.$message.error("请选择状态一致的数据！");
      }
      if ([...s][0] != 3) {
        return this.$message.error("请选择状态为禁用数据！");
      }
      this.$confirm("确认要启用这条课程, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$api.course
            .enableCourse({
              courseIds: courseId.join(','),
              state: 1, //状态 3禁用 1启用
            })
            .then((d) => {
              if (d.code == 200) {
                this.$message({
                  type: "success",
                  message: "启用成功",
                });
                this.getList(this.currentPage, this.pageSize);
              } else {
                this.$message.error(d.msg);
              }
            });
        })
        .catch(() => {
          this.$message.info("已取消启用");
        });
    },
    //禁用
    disable() {
      if (this.tableSelection.length < 1) {
        this.$message.error("请选择要操作的数据！");
        return;
      }
      let ids = this.tableSelection.map((e) => {
        return e.state;
      });
      let courseId = this.tableSelection.map((e) => {
        return e.courseId;
      });
      let s = new Set(ids);
      if ([...s].length != 1) {
        return this.$message.error("请选择状态一致的数据！");
      }
      if ([...s][0] != 1) {
        return this.$message.error("请选择状态为启用数据！");
      }
      this.$confirm("确认要禁用这条课程, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$api.course
            .enableCourse({
              courseIds: courseId.join(','),
              state: 3, //状态 3禁用 1启用
            })
            .then((d) => {
              if (d.code == 200) {
                this.$message({
                  type: "success",
                  message: "禁用成功",
                });
                this.getList(this.currentPage, this.pageSize);
              } else {
                this.$message.error(d.msg);
              }
            });
        })
        .catch(() => {
          this.$message.info("已取消禁用");
        });
    },
    editBanner(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$api.course
            .editCourse({
              courseId: this.EditForm.courseId,
              courseType: this.EditForm.courseType,
              headImg: this.EditForm.headImg,
              title: this.EditForm.title,
              defId: this.EditForm.defId,
              gradeId: this.EditForm.gradeId,
              moldId: this.EditForm.moldId,
              textbookId: this.EditForm.textbookId,
              unitId: this.EditForm.unitId,
              versionId: this.EditForm.versionId
            })
            .then((d) => {
              if (d.code == 200) {
                this.$message.success("编辑课程信息成功");
                this.getList(this.currentPage, this.pageSize);
                //  this.$refs.child.clearText();
                this.dialogEditFormVisible = false;
              } else {
                this.$message.error(d.msg);
              }
            });
        }
      })


    },

    geEdittUrl(item) {
      // this.EditAddfile = item.data.url;
      this.EditAddfile = item;
      // console.log(this.Adaddfile);
      this.$message({
        type: "success",
        message: "图片上传成功",
      });
    },
    getProductList() {
      this.$api.store
        .getStoreList({
          pageno: 1,
          pagesize: 200,
        })
        .then((d) => {
          if (d.code == 1) {
            this.ProductList = d.data;
          }
        });
    },
    getGoodsList() {
      this.$api.goods.getStoreGoodsList().then((d) => {
        if (d.code == 1) {
          d.data.forEach((item) => {
            if (item.enable == 1) {
              this.GoodsList.push(item);
            }
          });

          // this.GoodsList = d.data;
        }
      });
    },
    getList(curr, page) {
      this.$api.course
        .getCourseList({
          current: curr,
          size: page,
        })
        .then((d) => {
          if (d.code == 200) {
            this.tableData = d.data;
            this.total = d.totalCount;
            console.log(d.data);
          }
        });
    },
    getUrlAd(item) {
      this.createForm.addfile = item;
      // console.log(item);
      this.isShow = true;
      // console.log(this.Adaddfile);
      this.$message({
        type: "success",
        message: "图片上传成功",
      });
      // console.log(this.editimg);
    },
    showEdit() {
      if (this.createForm.bannerType == 1) {
        this.isShowEdit = false;
        this.isShowGoodsList = true;
        this.isShowProductList = false;
        this.isShowFeng = true;
      } else if (this.createForm.bannerType == 2) {
        this.isShowGoodsList = false;
        this.isShowEdit = false;
        this.isShowFeng = true;
        this.isShowProductList = true;
      } else if (this.createForm.bannerType == 3) {
        this.isShowGoodsList = false;
        this.isShowEdit = true;
        this.isShowFeng = true;
        this.isShowProductList = false;
      }
    },
    showEditType() {
      // console.log(this.EditForm.type);
      if (this.EditForm.type == 1) {
        this.isShowEditedit = false;
        this.isShowGoodsListEdit = true;
        this.isShowProductListEdit = false;
        this.isShowFengEdit = true;
      } else if (this.EditForm.type == 2) {
        this.isShowGoodsListEdit = false;
        this.isShowEditedit = false;
        this.isShowFengEdit = true;
        this.isShowProductListEdit = true;
      } else if (this.EditForm.type == 3) {
        this.isShowGoodsListEdit = false;
        this.isShowEditedit = true;
        this.isShowFengEdit = false;
        this.isShowProductListEdit = false;
      }
    },

    addCourse(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$api.course.addCourse({
            courseType: this.createForm.courseType,
            headImg: this.createForm.headImg,
            title: this.createForm.title,
            defId: this.createForm.defId,
            gradeId: this.createForm.gradeId,
            moldId: this.createForm.moldId,
            textbookId: this.createForm.textbookId,
            unitId: this.createForm.unitId,
            versionId: this.createForm.versionId
          }).then((d) => {
            if (d.code == 200) {
              this.dialogCreateFormVisible = false;
              this.$message.success("课程添加成功");
              // this.$refs.child.clearText();
              this.hasFile = false;
              this.getList(this.currentPage, this.pageSize);
            } else {
              this.$message.error(d.msg);
            }
          });
        }
      })

      //     let parmers = {};
      // if (this.createForm.type == 3) {

      //   parmers.bannerType = this.createForm.bannerType;
      //   parmers.bannerPosition = this.createForm.bannerPosition;

      //   parmers.link = this.createForm.link;
      //   parmers.linkType = 1;
      // } else if (this.createForm.type == 1) {
      //   parmers.bannerType = this.createForm.bannerType;
      //   parmers.bannerPosition = this.createForm.bannerPosition;
      //   parmers.bannerUrl = this.createForm.bannerUrl;
      //   parmers.link = this.createForm.link;
      //   parmers.linkType = 1;
      // } else if (this.createForm.type == 2) {
      //   // console.log(this.createForm.productList);
      //   parmers.objectId = this.createForm.productList;
      //   parmers.type = 2;
      //   (parmers.picUrl = this.createAddfile),
      //     (parmers.tokenUser = sessionStorage.getItem("token").token);
      // }
      // parmers.site = parseInt(this.createForm.region);

      //  parmers.

    },
    clearText() {
      this.content = "";
    },
    beforeAvatarUpload(file) {
      console.log(file, 231232)
      const isLt2M = file.size / 1024 / 1024 < 10;
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 10MB!');
      }
      return isLt2M;
    },
    getUrl(item) {
      this.hasFile = true;
      // console.log(this.addfile);
      // this.addfile = item.data.url;
      this.createForm.headImg = item;
      this.createAddfile = item;
      // console.log(item);
      // this.isShow = true;
      this.$message({
        type: "success",
        message: "图片上传成功",
      });
      // console.log(this.editimg);
    },
    //打开新增模态框
    add() {

      this.createForm = {
        "bannerType": '',
        "bannerPosition": '',
        "bannerUrl": '',
        "link": '',
        "linkType": '',

      }

      this.isShowGoodsList = false;
      this.isShowEdit = false;
      this.isShowFeng = false;
      this.isShowProductList = false;

      this.dialogCreateFormVisible = true;
    },
    //打开编辑模态框
    update() {
      if (this.tableSelection.length != 1) {
        this.$message.error('请选中一行数据');
        return
      }

      let row = this.tableSelection[0];
      console.log(row)
      let currType = row.courseType
      if (currType == 1) {
        console.log("1----------------------------------------")
        this.getListById(row.gradeId, 5)
        this.getListById(row.textbookId, 6)
      }
      this.changeType(row.courseType)
      this.hasFile = true;
      this.createAddfile = row.headImg
      this.EditForm = row;
      this.EditForm = {
        courseId: row.courseId,
        courseType: row.courseType,
        headImg: row.headImg,
        title: row.title,
        defId: Number(row.defId),
        gradeId: Number(row.gradeId),
        moldId: Number(row.moldId),
        textbookId: Number(row.textbookId),
        unitId: Number(row.unitId),
        versionId: Number(row.versionId)
      }
      // console.log(12312312312, this.EditForm);
      this.dialogEditFormVisible = true;
    },
    //删除数据
    del() {
      if (this.tableSelection.length != 1) {
        this.$message.error('请选中一行数据');
        return
      }
      this.$confirm("确认要删除这条banner, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$api.banner
            .updateState({
              bannerIds: this.tableSelection[0].bannerId,
              status: -1, //状态 0禁用 1启用
            })
            .then((d) => {
              if (d.code == 200) {
                this.$message({
                  type: "success",
                  message: "删除成功",
                });
                this.getList(this.currentPage, this.pageSize);
              } else {
                this.$message.error(d.msg);
              }
            });
        })
        .catch(() => {
          this.$message.info("已取消删除");
        });
    },
    search() { },
    handleReset() {
      this.$refs.searchForm.resetFields();
      this.search();
    },
    exec(fun) {
      if (this[fun]) {
        this.funTit = fun;
        this[fun]();
      } else {
        this.$message.error("方法未定义");
      }
    },
    tableSelectionChange(val) {
      this.tableSelection = val;
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.getList(this.currentPage, val);
      // eslint-disable-next-line no-console
      // console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getList(val, this.pageSize);
      // eslint-disable-next-line no-console
      // console.log(`当前页: ${val}`);
    },
  },
};
</script>

<style lang="scss" scoped>
.dialog-footer {
  margin-top: 50px;
}

.img-feng {
  width: 120px;
  height: 120px;
}

.goods {
  width: 500px;
}

.icon {
  display: flex;
  justify-content: space-between;

  i {
    font-size: 25px;
  }
}
</style>
